// 接口文件
const {Router} = require('express')
const router = new Router()
const db = require("./db.js");

// 学生-新增
router.post("/student/add",(req,res,next)=>{
    let body = req.body;
    let sqlParam = {
        sno: body.sno,
        sname: body.sname,
        ssex: body.ssex,
        sage: body.sage,
        sdepartion: body.sdepartion,
        specialty: body.specialty,
        class: body.class,
        phone: body.phone,
        mail: body.mail
    };
    db.dbAdd("student",sqlParam,res,next);
});

// 删除
router.post("/student/delete",(req,res,next)=>{
    let body = req.body;
    let sqlParam = {
        sno: body.sno,
        sname: body.sname,
        ssex: body.ssex,
        sage: body.sage,
        sdepartion: body.sdepartion,
        specialty: body.specialty,
        class: body.class,
        phone: body.phone,
        mail: body.mail
    };
    db.dbDelete("student",sqlParam,res,next);
});

// 更新，编辑
router.post("/student/update",(req,res,next) =>{
    let body = req.body;
    let sqlParam = {
        sage: body.sage,
        sdepartion: body.sdepartion,
        specialty: body.specialty,
        class: body.class,
        phone: body.phone,
        mail: body.mail,
        sno:body.sno   //注意顺序问题
    };
    db.dbUpdate("student",sqlParam,res,next);
})

// 查找全部数据
router.get("/student/all", (req, res, next) => {
    db.dbQueryAll("student", req, res, next);
});

//查找一条数据
router.get("/student/search",(req,res,next)=>{
    db.dbQueryById('student',req,res,next);
});


module.exports = router;